#include "accountfriends.h"
#include "accountfriend.h"
namespace Account {

Friends::Friends(QObject *parent) :
    QObject(parent)
{
}

Friend *Friends::append(int userId,
                        QString userName,
                        QString displayName,
                        QString avatar)
{
    if (m_map.contains(userId))
        return NULL;
    Friend *buddy = new Friend(userId, userName, displayName, avatar, this);
    m_map.insert(userId, buddy);
    m_list.append(buddy);
    return buddy;
}
int Friends::remove(int userId)
{
    if (!m_map.contains(userId))
        return -1;
    Friend *buddy = m_map.value(userId);
    m_map.remove(userId);

    int index = m_list.indexOf(buddy);
    m_list.removeOne(buddy);
    delete buddy;

    return index;
}

const Friend *Friends::find(int userId) const
{
    Map::ConstIterator iterator = m_map.find(userId);
    if (iterator == m_map.end())
        return NULL;
    return *iterator;
}
}
